-
Notifications
You must be signed in to change notification settings - Fork 407
Add UseCorrectParametersKind rule #2149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add UseCorrectParametersKind rule #2149
Conversation
* Consistent function parameters definition * Rule is disabled by default * Possible types of preferred function parameters are: "Inline", "ParamBlock"
|
@microsoft-github-policy-service agree |
|
@sdwheeler @michaeltlombardi @bergmeister Thank you in advance. |
bergmeister
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution and sorry for late review. I added Andy as well as he is the main code owner.
The rule might be a bit controversial as for some folks there is no 'correct' kind, therefore I suggest to name rule UseConsistentParametersKind for consistency with other rule names
| | [UseConsistentIndentation](./UseConsistentIndentation.md) | Warning | No | Yes | | ||
| | [UseConsistentWhitespace](./UseConsistentWhitespace.md) | Warning | No | Yes | | ||
| | [UseCorrectCasing](./UseCorrectCasing.md) | Information | No | Yes | | ||
| | [UseCorrectParametersKind](./UseCorrectParametersKind.md) | Warning | No | Yes | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please align the | with the other lines
|
|
||
| Rewrite function so it defines parameters as specified in the rule | ||
|
|
||
| ## Example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think also adding an incorrect example would be useful
|
|
||
| ## Description | ||
|
|
||
| All functions should have same parameters definition kind specified in the rule. Either using inline parameters in function definition or using param() block inside function body. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would try to better highlight there are only 2 kinds and what the consequences are of mixing them (is it just optical or does one get a compile or runtime error?).
Also, just talking from personal preference: I mix them because if I just need a simple function with arguments that are small enough to fit in one line, then I like the inline option but the moment things get more complicated (e.g. adding attributes/types, which makes inline hard to read), I use param block. We can definitely add this rule as-is since people can enable it if they think it's useful but just wondering whether it would be useful to some folks to have an optional configuration that allows them to enforce using param block when certain criteria are met (e.g. number of params, presence of attributes, etc.)
Consistent function parameters definition
Rule is disabled by default
Possible types of preferred function parameters are: "Inline", "ParamBlock"
PR Summary
This PSScriptAnalyzer rule enforces uniform parameter definitions ("Inline" or "ParamBlock") across functions, improving code readability and maintainability.
Key Benefits:
PR Checklist
.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.